package com.hjm.project.menubar.info.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.menubar.info.domain.MenubarInfo;
import com.hjm.project.menubar.info.service.IMenubarInfoService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 首页功能信息Controller
 * 
 * @author generator
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/menubar/info")
public class MenubarInfoController extends BaseController
{
    private String prefix = "menubar/info";

    @Autowired
    private IMenubarInfoService menubarInfoService;

    @RequiresPermissions("menubar:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询首页功能信息列表
     */
    @RequiresPermissions("menubar:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MenubarInfo menubarInfo)
    {
        startPage();
        List<MenubarInfo> list = menubarInfoService.selectMenubarInfoList(menubarInfo);
        return getDataTable(list);
    }

    /**
     * 导出首页功能信息列表
     */
    @RequiresPermissions("menubar:info:export")
    @Log(title = "首页功能信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MenubarInfo menubarInfo)
    {
        List<MenubarInfo> list = menubarInfoService.selectMenubarInfoList(menubarInfo);
        ExcelUtil<MenubarInfo> util = new ExcelUtil<MenubarInfo>(MenubarInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增首页功能信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页功能信息
     */
    @RequiresPermissions("menubar:info:add")
    @Log(title = "首页功能信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MenubarInfo menubarInfo)
    {
        return toAjax(menubarInfoService.insertMenubarInfo(menubarInfo));
    }

    /**
     * 修改首页功能信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MenubarInfo menubarInfo = menubarInfoService.selectMenubarInfoById(id);
        mmap.put("menubarInfo", menubarInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页功能信息
     */
    @RequiresPermissions("menubar:info:edit")
    @Log(title = "首页功能信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MenubarInfo menubarInfo)
    {
        return toAjax(menubarInfoService.updateMenubarInfo(menubarInfo));
    }

    /**
     * 删除首页功能信息
     */
    @RequiresPermissions("menubar:info:remove")
    @Log(title = "首页功能信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(menubarInfoService.deleteMenubarInfoByIds(ids));
    }
}
